package com.fcy.teamwork.widget

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView

class PortraitView(context: Context, attributeSet: AttributeSet? = null) :
    AppCompatImageView(context, attributeSet) {
    private val path = Path()

    override fun onDraw(canvas: Canvas?) {
        canvas?.apply {
            scaleType = ScaleType.CENTER_CROP
            val radius = Math.min(measuredHeight / 2, measuredWidth / 2)
            path.addCircle(
                (width / 2).toFloat(),
                (height / 2).toFloat(),
                radius.toFloat(),
                Path.Direction.CW
            )
            clipPath(path)
        }
        super.onDraw(canvas)
    }

}